package schedules;

import static org.quartz.CronScheduleBuilder.cronSchedule;
import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;

import java.util.Date;

import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CronTriggerEjecQ2 {
	  public void run() throws Exception {
	        Logger log = LoggerFactory.getLogger(CronTriggerEjecCero.class);

		        log.info("------- Initializing -------------------");

		        // First we must get a reference to a scheduler
		        SchedulerFactory sf = new StdSchedulerFactory();
		        Scheduler sched = sf.getScheduler();

		        log.info("------- Initialization Complete --------");

		        log.info("------- Scheduling Jobs ----------------");

		        // jobs can be scheduled before sched.start() has been called

		        // job 1 will run every 20 seconds
		        JobDetail job = newJob(senToJMSJob.class)
		            .withIdentity("job1", "group1")
		            .build();
		        
		        CronTrigger trigger = newTrigger()
		            .withIdentity("trigger1", "group1")
		            .withSchedule(cronSchedule("0 0/1 * * * ?"))
		            .build();

		        Date ft = sched.scheduleJob(job, trigger);
		        log.info(job.getKey() + " has been scheduled to run at: " + ft
		                + " and repeat based on expression: "
		                + trigger.getCronExpression());   
		       
		      try {
	        
		    	
		    	// sched.scheduleJob(job,trigger); 
		    	 sched.start();
	          } catch (Exception e) {
	      }

	    

	  }
		  
	  public void stop(){
		  
			  
	  }
		  
		  

	  public static void main(String[] args) throws Exception {

		  CronTriggerEjecQ2 example = new CronTriggerEjecQ2();
	      example.run();
	  }

}
